//
//  HomeInvestBindCell.m
//  LingQian
//
//  Created by xieyingze on 2018/1/21.
//  Copyright © 2018年 xieyingze. All rights reserved.
//

#import "HomeInvestBindCell.h"

@interface HomeInvestBindCell()
@property (nonatomic, strong) UIView *mainView;
@property (nonatomic, strong) BaseNextButton *investButton;
@property (nonatomic, strong) BaseLabel *rateNumberLabel;
@end

@implementation HomeInvestBindCell

+ (instancetype)cellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath {
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    static NSString *cellId = @"HomeInvestBindCell";
    HomeInvestBindCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (cell == nil) {
        cell = [[HomeInvestBindCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
    }
    return cell;
}

#pragma mark - init

- (void)initData {
    self.backgroundColor = kCOLOR_clear;
}

- (void)initSubView {
    [self addSubview:self.mainView];
}

- (void)autoLayoutSubviews {
    [self.mainView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@0).insets(UIEdgeInsetsMake(10, 20, 10, 20));
    }];
}

- (void)bindViewModel {
}

#pragma mark - Method


#pragma mark - Interface


#pragma mark - Setter

- (void)setViewModel:(HomeViewModel *)viewModel {
    _viewModel = viewModel;
    [self refreshUI];
}

- (void)refreshUI {
    self.rateNumberLabel.textColor = KCOLOR_mainColor;
    [self.rateNumberLabel setViewShadow:[KCOLOR_mainColor colorWithAlphaComponent:0.6] offset:CGSizeMake(0, 0) radius:kUI_ShawRadius/5];
//    self.investButton.backgroundColor = self.investButton.available ? KCOLOR_mainColor : [KCOLOR_mainColor colorWithAlphaComponent:0.5];
    self.investButton.available = NO;
}

#pragma mark - Getter

- (UIView *)mainView {
    if (!_mainView) {
        _mainView = [UIView new];
        _mainView.backgroundColor = kCOLOR_white;
        _mainView.layer.cornerRadius = kUI_LayerCorner;
        [_mainView setViewShadow:kCOLOR_shadowLight offset:CGSizeMake(0, 0) radius:kUI_ShawRadius];
        
        //历史年化
        BaseLabel *rateLabel = [BaseLabel new];
        [rateLabel setViewShadow:KCOLOR_lightFont offset:CGSizeMake(0, 0) radius:kUI_ShawRadius/2];
        [rateLabel setLabelStyle:@"新手专享 | 历史年化" textColor:KCOLOR_lightFont textFont:kFONT_mainFont(10) texrAlignment:NSTextAlignmentCenter];
        [_mainView addSubview:rateLabel];
        [rateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(@40);
            make.centerX.equalTo(@0);
            make.height.equalTo(@10);
        }];
        
        BaseLabel *rateNumberLabel = [BaseLabel new];
        [rateNumberLabel setLabelStyle:@"13.00" textColor:KCOLOR_heavyFont textFont:kFONT_mainBoldFont(30) texrAlignment:NSTextAlignmentCenter];
        self.rateNumberLabel = rateNumberLabel;
        [_mainView addSubview:rateNumberLabel];
        [rateNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(rateLabel.mas_bottom).offset(10);
            make.centerX.equalTo(@0);
            make.height.equalTo(@30);
        }];
        
        UIView *line = [UIView new];
        line.backgroundColor = kCOLOR_lightLine;
        [_mainView addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(rateNumberLabel.mas_bottom).offset(30);
            make.left.equalTo(@40);
            make.right.equalTo(@-40);
            make.height.equalTo(@0.5);
        }];
        
        //历史年化
        BaseLabel *descriptionLabel = [BaseLabel new];
        [descriptionLabel setLabelStyle:@"15天  |  剩余0.00万  |  100元起购" textColor:KCOLOR_lightFont textFont:kFONT_mainFont(10) texrAlignment:NSTextAlignmentCenter];
        [_mainView addSubview:descriptionLabel];
        [descriptionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(line.mas_bottom).offset(20);
            make.centerX.equalTo(@0);
            make.height.equalTo(@10);
        }];
        
        BaseNextButton *investButton = [BaseNextButton new];
        investButton.available = NO;
        investButton.title = @"立即购买";
        self.investButton = investButton;
        [_mainView addSubview:investButton];
        [investButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(descriptionLabel.mas_bottom).offset(60);
            make.centerX.equalTo(@0);
            make.width.equalTo(@(200 * kUI_Percent));
            make.height.equalTo(@(kUI_ButtonHeight));
        }];
        
        BaseLabel *joinInLabel = [BaseLabel new];
        [joinInLabel setLabelStyle:@"已加入10人" textColor:KCOLOR_lightFont textFont:kFONT_mainFont(10) texrAlignment:NSTextAlignmentCenter];
        [_mainView addSubview:joinInLabel];
        [joinInLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(investButton.mas_bottom).offset(10);
            make.centerX.equalTo(@0);
            make.height.equalTo(@10);
        }];
    }
    return _mainView;
}
@end
